package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Region;
import cn.wolfcode.wolf2w.domain.StrategyCatalog;
import cn.wolfcode.wolf2w.service.*;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("destinations")
public class DestinationController {

	@Autowired
	private IDestinationService destinationService;
	@Autowired
	private IRegionService regionService;
	@Autowired
	private IStrategyService strategyService;
	@Autowired
	private IStrategyCatalogService strategyCatalogService;
	@Autowired
	private ITravelService travelService;


	@GetMapping("/hotRegion")
	
	public Object hotRegion() {
		List<Region> regions = regionService.findByHotRegion();
		return JsonResult.success(regions);
	}

	@GetMapping("/search")
	
	public Object search(String regionId) {
		List<Destination> destinations = destinationService.search(regionId);
		return JsonResult.success(destinations);
	}

	@GetMapping("/strategies/viewnumTop3")
	
	public Object strategies_ViewnumTop3(String destId) {
		return JsonResult.success(strategyService.queryByViewnum(destId));
	}

	@GetMapping("/travels/viewnumTop3")
	
	public Object travels_ViewnumTop3(String destId) {
		return JsonResult.success(travelService.queryByViewnum(destId));
	}


	@GetMapping("/toasts")
	
	public Object toasts(String destId) {
		List<Destination> data = destinationService.queryParent(new ArrayList<>(), destId);
		Collections.reverse(data);
		return JsonResult.success(data);
	}

	@GetMapping("/catalogs")
	
	public Object catalogs(String destId) {
		List<StrategyCatalog> strategyCatalogs = strategyCatalogService.queryCatalogsByDestId(destId);
		return JsonResult.success(strategyCatalogs);
	}

	@GetMapping("/list")
	
	public Object list() {
		List<Destination> list = destinationService.list();
		return JsonResult.success(list);
	}
}